In [33]:
import datetime
import json
from pprint import pprint
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
plotly.tools.set_credentials_file(username='zb1261096', api_key='skaEiEgl40N5Rs6LCgO9')
import requests
import warnings
warnings.filterwarnings('ignore')
import numpy as np
import matplotlib.pyplot as plt
import mpld3
mpld3.enable_notebook()
from matplotlib.widgets import Slider, Button, RadioButtons
from matplotlib import interactive
interactive(True)
import IPython
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:95% !important; }</style>"))
In [2]:
%%html

<style>

.output_wrapper, .output {
    height:auto !important;
    max-height:2400px;  /* your desired max-height here */
}
.output_scroll {
    box-shadow:none !important;
    webkit-box-shadow:none !important;
}

</style>

USER Info

In [3]:
#df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/Mining-BTC-180.csv')
ques_data = json.load(open('autismema-question_sets-export.json'))
user_data = json.load(open('Zachery McCann_autismema-ivptwbfU29S3Bp09NUbx08JoLMl1-export.json'))
q_set = ques_data['general']

q_id_map = {}
all_question_list = []
index = 0
for ques in q_set['question']:
    if ques != None:
        all_question_list.append(ques["text"])
        q_id_map[ques["id"]] = index
        index = index + 1
all_ema = [[],[],[]]
all_ema[0].append("Question")
all_ema[1].append("Question")
all_ema[2].append("Question")

all_answer_list = [[],[],[]]
all_answer_list[0].append(all_question_list)
all_answer_list[1].append(all_question_list)
all_answer_list[2].append(all_question_list)
for ema in user_data['ema']:
    if ema != None:
        answer_list = ["N/A"] * len(all_question_list)
        for answer in ema['usersAllEMAAnswers'].values():
            i = q_id_map[answer['questionId']]
            answer_list[i] = answer['answer']
        d = datetime.datetime.fromtimestamp(float(ema["timeUTC"])/1000.0).strftime("%Y-%m-%d <br> %H:%M")
        if ema["questionSet"] == "general":
            all_answer_list[0].append(answer_list)
            all_ema[0].append("Ema: <br>"+d)
        elif ema["questionSet"] == "general2":
            all_answer_list[1].append(answer_list)
            all_ema[1].append("Ema: <br>"+d)
        elif ema["questionSet"] == "general3":
            all_answer_list[2].append(answer_list)
            all_ema[2].append("Ema: <br>"+d)
        else:
            print("")

EMA 1 : All Questionnaire Answer

In [4]:
c_width = [1] * len(all_ema[0])
c_width[0] = 2
table = go.Table(
    columnwidth=c_width,
    header=dict(
        height = 50,
        values=all_ema[0],
        font=dict(size=18),
       # line = dict(color='rgb(50, 50, 50)'),
        align = 'left',
        #fill = dict(color='#d562be'),
    ),
    cells=dict(
        values=all_answer_list[0],
         font=dict(size=14),
        height = 40,
        line = dict(color='rgb(50, 50, 50)'),
        align = 'left',
        fill = dict(color='#f5f5fa')
        
        
    )
)
py.iplot([table], filename='EMA 1')
Out[4]:

EMA 2: All Questionnaire Answer

In [5]:
c_width = [1] * len(all_ema[1])
c_width[0] = 2
table = go.Table(
    columnwidth=[2,  1, 1,1, 1, 1],
    header=dict(
        height = 50,
        values=all_ema[1],
        font=dict(size=18),
       # line = dict(color='rgb(50, 50, 50)'),
        align = 'left',
        #fill = dict(color='#d562be'),
    ),
    cells=dict(
        height = 40,
        font=dict(size=14),
        values=all_answer_list[1],
        line = dict(color='rgb(50, 50, 50)'),
        align = 'left',
        fill = dict(color='#f5f5fa')
        
    )
)
py.iplot([table], filename='EMA 2')
Out[5]:

EMA 3: All Questionnaire Answer

In [6]:
c_width = [1] * len(all_ema[2])
c_width[0] = 2
table = go.Table(
    columnwidth=c_width,
    header=dict(
        values=all_ema[2],
         font=dict(size=18),
        height = 50,
       # line = dict(color='rgb(50, 50, 50)'),
        align = 'left',
        #fill = dict(color='#d562be'),
    ),
    cells=dict(
        font=dict(size=14),
        height = 40,
        values=all_answer_list[2],
        line = dict(color='rgb(50, 50, 50)'),
        align = 'left',
        fill = dict(color='#f5f5fa')
        
    )
)
py.iplot([table], filename='EMA 3')
Out[6]:
In [7]:
x_list = []
y_list = []
light_dict = {}
for key, value in sorted(user_data['sensors']['light'].items()):
    d = datetime.datetime.fromtimestamp(float(key)/1000.0)
    x_list.append(d)
    y_list.append(float(value))
    light_dict[d] = float(value)
In [8]:
plt.rcParams["figure.figsize"] = (22,18)
plt.xlim(x_list[0],x_list[600])
plt.plot(x_list,y_list)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()
#axes.set_xlim([min(x_list),max(x_list)])
#axes.set_ylim([min(y_list),max(y_list)])
plt.show()
In [26]:
x_list_noise = []
y_list_noise = []
noise_dict = {}
for key, value in sorted(user_data['sensors']['noise'].items()):
    d = datetime.datetime.fromtimestamp(float(key)/1000.0)
    x_list_noise.append(d)
    y_list_noise.append(float(value))
    noise_dict[d] = float(value)
In [27]:
#plt.yticks(np.arange(min(y_list),max(y_list), 3000))
plt.rcParams["figure.figsize"] = (22,18)
#plt.axis([x_list[0],x_list[200],0,max(y_list)+1000])
plt.xlim(x_list_noise[0],x_list_noise[300])
plt.plot(x_list_noise,y_list_noise)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()

#my_xticks = ['a', 'b', 'c', 'd']
#plt.xticks(x, my_xticks)
plt.show()
In [28]:
r = requests.get('https://api.fitbit.com/1/user/-/activities/heart/date/2018-02-21/1d/1sec/time/00:00/16:00.json', headers={'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2RzdHVk4iLCJhdWQiOiIyMkNNQ0giLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJzY29wZXMiOiJyc29jIHJhY3QgcnNldCBybG9jIHJ3ZWkgcmhyIHJudXQgcnBybyByc2xlIiwiZXhwIjoxNTIyMTE0OTUxLCJpYXQiOjE1MTk1MjI5NTF9.0inpK-NFY9GvHkKIlAPbkqh5ZRhOlXlHx_-Z9t9l6xU'})
In [29]:
heart_rate_json = r.json()
In [30]:
x_list = []
y_list = []
heart_rate_dict = {}
date = "2018-02-15"
for answer in heart_rate_json['activities-heart-intraday']['dataset']:
    d = datetime.datetime.strptime(date+" "+answer['time'], '%Y-%m-%d %H:%M:%S')
    x_list.append(d)
    y_list.append(int(answer['value']))
    heart_rate_dict[d] = int(answer['value'])
In [31]:
plt.rcParams["figure.figsize"] = (22,18)
#plt.axis([x_list[0],x_list[200],0,max(y_list)+1000])
plt.xlim(x_list[0],x_list[200])
plt.plot(x_list,y_list)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()

#my_xticks = ['a', 'b', 'c', 'd']
#plt.xticks(x, my_xticks)
plt.show()
In [36]:
print("N/A")

max_val = max(y_list_noise)
norm_y_list_noise = [float(i)*100/max_val for i in y_list_noise]


plt.figure(1)
ax1 = plt.subplot(211)
plt.xlim(x_list_noise[0],x_list_noise[200])
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()
plt.plot(x_list_noise,norm_y_list_noise)

plt.subplot(212,sharex = ax1)

plt.xlim(x_list[0],x_list[200])
plt.ylim(0,200)
plt.plot(x_list,y_list)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()
N/A
In [16]:
all_dates = []
for key, value in noise_dict.items():
    all_dates.append(key)
for key, value in heart_rate_dict.items():
    all_dates.append(key)
all_dates = sorted(all_dates)
print(all_dates[0:10])

y_list_heart_rate =[]
y_list_noise =[]

for key in all_dates:
    if key in noise_dict:
        y_list_noise.append(noise_dict[key])
    else:
        y_list_noise.append(np.nan)
        
    if  key in heart_rate_dict:
        y_list_heart_rate.append(heart_rate_dict[key])
    else:
        y_list_heart_rate.append(np.nan)

print (len(y_list_heart_rate))
print (len(y_list_heart_rate))
[datetime.datetime(2018, 2, 15, 0, 0, 4), datetime.datetime(2018, 2, 15, 0, 0, 9), datetime.datetime(2018, 2, 15, 0, 0, 24), datetime.datetime(2018, 2, 15, 0, 0, 26), datetime.datetime(2018, 2, 15, 0, 0, 36), datetime.datetime(2018, 2, 15, 0, 0, 46), datetime.datetime(2018, 2, 15, 0, 0, 51), datetime.datetime(2018, 2, 15, 0, 1, 6), datetime.datetime(2018, 2, 15, 0, 1, 11), datetime.datetime(2018, 2, 15, 0, 1, 26)]
90186
90186
In [120]:
'''
plt.rcParams["figure.figsize"] = (22,18)
#plt.axis([x_list[0],x_list[200],0,max(y_list)+1000])
#plt.xlim(all_dates[0],all_dates[200])


plt.figure(1)
plt.subplot(211)
plt.plot(x_list,y_list)

plt.subplot(212)

plt.plot(x_list_noise,y_list_noise)

#plt.plot(all_dates,y_list_heart_rate)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()

#my_xticks = ['a', 'b', 'c', 'd']
#plt.xticks(x, my_xticks)
plt.show()
'''
Out[120]:
'\nplt.rcParams["figure.figsize"] = (22,18)\n#plt.axis([x_list[0],x_list[200],0,max(y_list)+1000])\n#plt.xlim(all_dates[0],all_dates[200])\n\n\nplt.figure(1)\nplt.subplot(211)\nplt.plot(x_list,y_list)\n\nplt.subplot(212)\n\nplt.plot(x_list_noise,y_list_noise)\n\n#plt.plot(all_dates,y_list_heart_rate)\n# beautify the x-labels\nplt.gcf().autofmt_xdate()\naxes = plt.gca()\n\n#my_xticks = [\'a\', \'b\', \'c\', \'d\']\n#plt.xticks(x, my_xticks)\nplt.show()\n'